package com.kgcx.gateway.api;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 吴刚林
 * @date 2018/5/14
 */
public class ApiUtils {
    private static List<String> apis = new ArrayList<>();

    static {
        apis.addAll(toList(Organization.NAME, Organization.API));
        apis.addAll(toList(System.NAME, System.API));
        apis.addAll(toList(Order.NAME, Order.API));
        apis.addAll(toList(Price.NAME, Price.API));
        apis.addAll(toList(Coupon.NAME, Coupon.API));
        apis.addAll(toList(Schedule.NAME, Schedule.API));
    }

    public static boolean isApi(String url) {
        return CollectionUtils.isNotEmpty(apis) && apis.contains(url);
    }

    public static boolean notApi(String url) {
        return !isApi(url);
    }

    private static List<String> toList(String name, String[] arr) {
        List<String> list = new ArrayList<>();
        if (ArrayUtils.isNotEmpty(arr)) {
            for (String s : arr) {
                list.add("/" + name + s.trim());
            }
        }
        return list;
    }


}
